Skip to content

Add lazy option to QuantumOpticsRepr#85

Open
GrovyleX wants to merge 1 commit into
qojulia:mainfrom
GrovyleX:lazy-quantumopticsrepr
Open

Add lazy option to QuantumOpticsRepr#85
GrovyleX wants to merge 1 commit into
qojulia:mainfrom
GrovyleX:lazy-quantumopticsrepr

Conversation

@GrovyleX

@GrovyleX GrovyleX commented Jun 13, 2026

Copy link
Copy Markdown

What this does

Adds an opt-in lazy::Bool=false field to QuantumOpticsRepr. On its own this does nothing
visible — it's the switch the companion QuantumSymbolics PR (QuantumSavory/QuantumSymbolics.jl#203) reads to decide whether
express builds eager matrices or QuantumOpticsBase's lazy operators (LazySum, LazyProduct,
LazyTensor). Together they implement qojulia/QuantumOptics.jl#521. The default is unchanged:
QuantumOpticsRepr() is still eager.

Keeping the existing constructors working

QuantumOpticsRepr is a Base.@kwdef struct, so naively adding a second field breaks the
positional call QuantumOpticsRepr(4) — it would start expecting two positional arguments. One
outer constructor restores it:

QuantumOpticsRepr(cutoff::Int) = QuantumOpticsRepr(; cutoff)

So nothing existing breaks and the option is purely additive:

  • QuantumOpticsRepr() → cutoff 2, eager
  • QuantumOpticsRepr(4) → cutoff 4, eager
  • QuantumOpticsRepr(cutoff=4)
  • QuantumOpticsRepr(lazy=true)
  • QuantumOpticsRepr(cutoff=4, lazy=true)

Why a field, and not a flag passed some other way

express caches its conversions in a Dict keyed on the representation value, and
QuantumOpticsRepr relies on the default structural ==/hash. Making lazy a real field means
an eager and a lazy representation of the same object compare unequal, so they get separate cache
slots and the cache can't hand back the wrong type. test/test_express.jl checks that invariant
plus all the constructor forms above.

Pkg.test() is green locally on Julia 1.12.6, including Aqua. CHANGELOG bumped to v0.4.3.

Part of qojulia/QuantumOptics.jl#521

AI disclosure

I used AI to help analyze the codebase understand different and help in implementation, but I worked out the @kwdef/constructor and caching details myself, verified them against how express actually keys its cache, and wrote
and ran the tests. I went through the whole diff and understand every line - happy to walk through
any of it.

Add a `lazy::Bool=false` field to `QuantumOpticsRepr` so downstream `express` conversions can opt into the lazy operator types of QuantumOpticsBase. An explicit `QuantumOpticsRepr(cutoff::Int)` constructor keeps the existing positional calling convention working, and the default representation is unchanged.

Part of qojulia/QuantumOptics.jl#521
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant